<?php
declare (strict_types=1);

namespace Plugin\Alarm\Model;

use Mine\MineModel;
use Plugin\Device\Model\RdDeviceRod;
use Plugin\Device\Model\RdDeviceSerial;
use Plugin\File\Model\RdFilePlaybackVideo;
use Plugin\Organization\Model\RdOrganizeAreaStand;

class RdAlarmWarnRecord extends MineModel
{
    /**
     * The table associated with the model.
     *
     * @var string|null
     */
    protected ?string $table = 'rd_alarm_warn_record';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected array $fillable = [
        'id', 'broadcast_id', 'msg_id', 'rod_id', 'stand_id', 'type', 'work_id', 'warning_time', 'device_id', 'risk_level', 'title', 'content', 'msg_type', 'created_at', 'updated_at'
    ];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected array $casts = [
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
        'id' => 'integer',
        'broadcast_id' => 'integer',
        'msg_id' => 'integer',
        'rod_id' => 'integer',
        'stand_id' => 'integer',
        'type' => 'integer',
        'work_id' => 'integer',
        'warning_time' => 'datetime',
        'device_id' => 'integer',
        'risk_level' => 'integer',
        'title' => 'string',
        'content' => 'string',
        'msg_type' => 'integer',
    ];

    public function broadcast()
    {
        return $this->belongsTo(RdAlarmBroadcastRecord::class, 'broadcast_id', 'id');
    }

    public function rod()
    {
        return $this->belongsTo(RdDeviceRod::class, 'rod_id', 'id');
    }

    public function device()
    {
        return $this->belongsTo(RdDeviceSerial::class, 'device_id', 'id');
    }

    public function stand()
    {
        return $this->belongsTo(RdOrganizeAreaStand::class, 'stand_id', 'id');
    }

    public function msg()
    {
        return $this->belongsTo(RdAlarmMsg::class, 'msg_id', 'id');
    }

    public function type()
    {
        return $this->hasOne(RdAlarmType::class, 'id', 'type');
    }

    public function  work()
    {
        return $this->hasOne(RdAlarmWork::class, 'id', 'work_id');
    }

    public function addr()
    {
        return $this->hasOne(RdDeviceSerial::class, 'id', 'device_id');
    }
}